import java.util.ArrayList;
import java.util.List;

public class Test05 {
    public static void main(String[] args) {
        /*
		2.定义测试类,进行测试
			(1)创建10个学生对象存入ArrayList集合中
         */
        List<Student2> list=new ArrayList<Student2>();
        list.add(new Student2("a",1,50));
        list.add(new Student2("b",3,87));
        list.add(new Student2("c",2,64));
        list.add(new Student2("d",9,90));
        list.add(new Student2("e",8,78));
        list.add(new Student2("f",4,82));
        list.add(new Student2("g",10,100));
        list.add(new Student2("h",7,66));
        list.add(new Student2("i",5,99));
        list.add(new Student2("j",6,60));
        maxScore(list);
        System.out.println(avg(list, allScore(list)));
        pass(list);

    }
    //打印最高分的学员姓名、年龄、成绩  [要求封装1个方法  参数是集合对象   返回值类型为Student]
    public static Student2 maxScore(List<Student2> list){
        int maxScore=list.get(0).getScore();
        Student2 maxStudent= list.get(0);
        for(int i=0;i<list.size();i++){
            if(maxScore<list.get(i).getScore()){
                maxScore=list.get(i).getScore();
            }
        }
        for(int i=0;i<list.size();i++){
            if(maxScore==list.get(i).getScore()){
                maxStudent= list.get(i);
                System.out.println(list.get(i));
            }
        }
        return maxStudent;
    }
    //打印10个学生的总成绩和平均分		 [要求封装两个方法完成]
    public static Integer allScore(List<Student2> list){
        Integer allScore=0;
        for(int i=0;i<list.size();i++){
            allScore+=list.get(i).getScore();
        }
        return allScore;
    }
    public static Double avg(List<Student2> list,Integer allScore){
        Double avg=0.0;
        avg=(double)(allScore/list.size());
        return avg;
    }
    //打印不及格的学员信息及数量		 [要求封装一个方法完成]
    public static void pass(List<Student2> list){
        for(int i=0;i<list.size();i++){
            if(60>list.get(i).getScore()){
                System.out.println(list.get(i));
            }
        }
    }
}
class Student2{
    /*
    定义Student类
			属性:
				姓名：String name
				年龄：int age
				成绩：int score
			行为:
				空参构造方法
				有参构造方法
				set和get方法
				toString方法
     */
    private String name;
    private int age;
    private int score;

    public Student2() {
    }

    public Student2(String name, int age, int score) {
        this.name = name;
        this.age = age;
        this.score = score;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getAge() {
        return age;
    }

    public void setAge(int age) {
        this.age = age;
    }

    public int getScore() {
        return score;
    }

    public void setScore(int score) {
        this.score = score;
    }

    @Override
    public String toString() {
        return "Student2{" +
                "name='" + name + '\'' +
                ", age=" + age +
                ", score=" + score +
                '}';
    }
}